package com.linkedList;

public class RemoveNthNodeFromEndofList0129_19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(-1,head);
        ListNode fast = dummy;
        while (n>0){
            fast = fast.next;
            n--;
        }
        ListNode low = dummy;
        while (fast.next != null){
            fast = fast.next;
            low = low.next;
        }
        low.next = low.next.next;
        return dummy.next;

    }
}
